﻿using Super.Admin.Utils.EventAggregator.EventType;
using Super.Admin.Utils.EventAggregator;
using Super.Admin.Utils.ThemeManager;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Super.Admin.Views.Main
{
    public partial class UcMainDrawerSettingShortcutSetting : UserControl
    {
        private bool _isLoad = false;
        public UcMainDrawerSettingShortcutSetting()
        {
            InitializeComponent();
            this.Load += UcMainDrawerSettingShortcutSetting_Load; ;
        }

        private void UcMainDrawerSettingShortcutSetting_Load(object? sender, EventArgs e)
        {
            _isLoad = true;
            // 初始化本地参数
            InitializeLoadConfig();
            _isLoad = false;
        }

        private void InitializeLoadConfig()
        {
            LblGlobalSearchTxt.Text = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.GlobalSearch.ShortcutKeysText ;
            LblLogoutTxt.Text = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Logout.ShortcutKeysText ;
            LblLockScreenTxt.Text = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.LockScreen.ShortcutKeysText ;
            LblRefreshViewTxt.Text = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.RefreshView.ShortcutKeysText ;
            LblFullScreenTxt.Text = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.FullScreen.ShortcutKeysText ;
            BtnSwitchEnableGlobalShortcut.Checked = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Enable;
            BtnSwitchEnableGlobalSearchShortcut.Checked = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.GlobalSearch.EnableShortcut;
            BtnSwitchEnableLogoutShortcut.Checked = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.Logout.EnableShortcut;
            BtnSwitchEnableLockScreenShortcut.Checked = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.LockScreen.EnableShortcut;
            BtnSwitchEnableRefreshViewShortcut.Checked = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.RefreshView.EnableShortcut;
            BtnSwitchEnableFullScreenShortcut.Checked = ThemeSettingHelper.Instance.ThemeConfig.ShortcutSettings.GlobalShortcut.FullScreen.EnableShortcut;
        }

        private void BtnSwitch_CheckedChanged(object sender, AntdUI.BoolEventArgs e)
        {
            if (_isLoad) return;
            AntdUI.Switch @switch = (AntdUI.Switch)sender;
            switch (@switch.Name)
            {
                case "BtnSwitchEnableGlobalShortcut":
                    EventAggregator.Default.Publish<ShortcutSettingEvent>(new ShortcutSettingEvent { Type = ShortcutSettingEvent.ShortcutSettingType.EnableGlobalShortcut, Value = e.Value });
                    break;
                case "BtnSwitchEnableGlobalSearchShortcut":
                    EventAggregator.Default.Publish<ShortcutSettingEvent>(new ShortcutSettingEvent { Type = ShortcutSettingEvent.ShortcutSettingType.EnableGlobalSearchShortcut, Value = e.Value });
                    break;
                case "BtnSwitchEnableLogoutShortcut":
                    EventAggregator.Default.Publish<ShortcutSettingEvent>(new ShortcutSettingEvent { Type = ShortcutSettingEvent.ShortcutSettingType.EnableLogoutShortcut, Value = e.Value });
                    break;
                case "BtnSwitchEnableLockScreenShortcut":
                    EventAggregator.Default.Publish<ShortcutSettingEvent>(new ShortcutSettingEvent { Type = ShortcutSettingEvent.ShortcutSettingType.EnableLockScreenShortcut, Value = e.Value });
                    break;
                case "BtnSwitchEnableRefreshViewShortcut":
                    EventAggregator.Default.Publish<ShortcutSettingEvent>(new ShortcutSettingEvent { Type = ShortcutSettingEvent.ShortcutSettingType.EnableRefreshViewShortcut, Value = e.Value });
                    break;
                case "BtnSwitchEnableFullScreenShortcut":
                    EventAggregator.Default.Publish<ShortcutSettingEvent>(new ShortcutSettingEvent { Type = ShortcutSettingEvent.ShortcutSettingType.EnableFullScreenShortcut, Value = e.Value });
                    break;
            }
        }
    }
}
